<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/12/04
 * Time: 11:13
 */

namespace app\common\model;

use think\Model;

class Share extends Model
{
    protected $pk = 'id';
    protected $table = 'vote_shareset';

    /**
     * 获取数据
     */
    public function getAll()
    {
        return $this->order('id')->find();
    }

    /**
     * @param $data
     * @return array
     * 设置数据
     */
    public function upd($data)
    {
        $result = $this->allowField(true)->save($data, [$this->pk => $data['id']]);
        if ($result) {
            return ['valid' => 1, 'msg' => '设置成功'];
        } else {
            return ['valid' => 0, 'msg' => $this->getError()];
        }

    }

    public function add($data)
    {
        $result = $this->validate(true)->allowField(true)->save($data);
        if ($result) {
            return ['valid' => 1, 'msg' => '设置成功'];
        } else {
            return ['valid' => 0, 'msg' => $this->getError()];
        }

    }
}